package balmysundaycandy.morelowlevel.sample.controller.others;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import balmysundaycandy.morelowlevel.sample.controller.PathElement;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyRange;

public class OneController extends Controller {

	@Override
	protected Navigation run() {
		DatastoreService service = DatastoreServiceFactory.getDatastoreService();
		KeyRange parentKeyRange = service.allocateIds("parent", 1);
		Key parentKey = parentKeyRange.getStart();
		KeyRange childKeyRange = service.allocateIds(parentKey, "child", 1);
		Key childKey = childKeyRange.getStart();

		@SuppressWarnings("unused")
		Entity parent = new Entity(parentKey);
		Entity child = new Entity(childKey);

		service.put(child);
		
		return forward(PathElement.JSP_PATH + "/index.jsp");
	}

}
